import IEntitySystem from "../../base/ECSR/IEntitySystem";
import GameClientData from "../data/GameClientData"
import Guid from "../../../common/utils/Guid";
import BubbleComponent, {BubbleColorType} from "../components/BubbleComponent";
import AimComponent from "../components/AimComponent";
import TransformComponent from "../../base/ECSR/components/TransformComponent";
import NotifyMgr, { SelfNotification } from "../../base/notify/NotifyMgr";
import Notifications from "../Notifications";

export default class ReadBubbleSystem extends IEntitySystem
{
    constructor(world)
    {
        super(world);
    }
    // 每逻辑帧调用
    Execute()
    {
        // 目前没有发射的球
        // cc.log("ReadBubbleSystem|Execute|---1----" + GameClientData.selfControlEntityId);
        if(GameClientData.selfControlEntityId === "")
        {
            let bubbleItemId = Guid.guid();
            let bubbleEntity = this.world.AddEntity(bubbleItemId);
            var bubbleCom = new BubbleComponent();
            let aimCom = new AimComponent();
            let transCom = new TransformComponent(AimComponent.aimPoint);

            bubbleCom.colorType = BubbleColorType.RED;
            
            aimCom.enable = false;

            bubbleEntity.AddComponent(transCom);
            bubbleEntity.AddComponent(bubbleCom);
            bubbleEntity.AddComponent(aimCom);
            
            GameClientData.selfControlEntityId = bubbleItemId;
            // cc.log("ReadBubbleSystem|Execute|---2----" + GameClientData.selfControlEntityId);
            NotifyMgr.Instance().Send(Notifications.CreateReadBubble, new SelfNotification("", [bubbleCom], this));

        }
    }
}